package com.zisu.aradvertising.controller;

import com.zisu.aradvertising.pojo.JsonResult;
import com.zisu.aradvertising.pojo.Result;
import com.zisu.aradvertising.pojo.Video;
import com.zisu.aradvertising.service.VideoService;
import com.zisu.aradvertising.service.impl.VideoImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/video")
public class VideoController {
    @Autowired
    VideoImpl Videoimpl;
    @Autowired
    private VideoService videoService;

    @GetMapping("1")
    public String hello() {
        return "Hello";
    }

    @RequestMapping(value ="/upload",method = RequestMethod.POST)
    @ResponseBody
    public JsonResult uploadVideo(@RequestParam(value = "videoFile")MultipartFile videoFile){
        return Videoimpl.uploadVideo(videoFile);
    }

    @RequestMapping(value ="/analyze",method = RequestMethod.POST)
    @ResponseBody
    public JsonResult analyzeVideo(@RequestParam(value = "videoFile")MultipartFile videoFile) throws InterruptedException {
        System.out.println("进入");
        return Videoimpl.analyzeVideo(videoFile);
    }

    //OSS视频处理接口
    @PostMapping("/videoUpload")
    @ResponseBody
    public Result<Video> videouploadController(@RequestParam MultipartFile videoFile, @RequestParam MultipartFile pictureFile,
                                         @RequestParam int cid,@RequestParam String vname,@RequestParam String vstyle) {
        Video video = videoService.videouploadService(videoFile,pictureFile,cid,vname,vstyle);
        if (video != null) {
            return Result.success(video, "上传成功!");
        } else{
            return  Result.error("456","上传失败!");
        }
    }

    //信息编辑界面
    @PostMapping("/videoedit")
    public Result<Video> videoController(@RequestParam int vid, @RequestParam String vrequirement,
                                         @RequestParam String videointroduction) {
        Video video = videoService.editService(vid, vrequirement,videointroduction);
        if (video != null) {
            return Result.success(video, "编辑成功!");
        } else{
            return  Result.error("123","编辑错误!");
        }
    }
    //返回所有视频的信息
    @PostMapping("/findall")
    public Result<List<Video>> findallController() {
        List<Video> list= videoService.findallService();
        if (list != null) {
            return Result.success(list, "查询成功");
        } else{
            return  Result.error("123","查询失败!");
        }
    }

}
